//go:build prod

package main

import (
	"embed"

	"gitee.com/micro-plat/sso/ssov5"
	"github.com/micro-plat/hydra"
	"github.com/micro-plat/hydra/conf/server/api"
	"github.com/micro-plat/hydra/conf/server/auth"
	"github.com/micro-plat/hydra/conf/server/auth/jwt"
	"github.com/micro-plat/hydra/conf/server/header"
	"github.com/micro-plat/hydra/conf/server/processor"
	"github.com/micro-plat/hydra/conf/server/static"
)

//go:embed web/dist
var staticFs embed.FS
var archive = "web/dist"

//bindConf 绑定启动配置， 启动时检查注册中心配置是否存在，不存在则引导用户输入配置参数并自动创建到注册中心
func init() {
	hydra.OnReady(func() error {

		hydra.Conf.Vars().DB().Custom("db", "encrypt:cbc/pkcs5:0359e6dbb6f414c8f9561280089a23e97d3864eec5cd7efc4fc6948c5751c87b0f7bc22276e522414422e392f7e2f6f44653d3807965ea291b7dc84d0bcfe710b43efb7c2c816c2cff7f6ab5da65e839b14e2ffb541378246970fe0189018ee8e9ee21406234d713088e459d93be05927966828ae5b8c032cfdf15dc2fd08b9d7ea675e7b115286e647bf5dee00ceb5ec213b4d0ce1eb1e85804876ac8feb2328841a8feb6b37cbc")

		//登录的界面配置
		hydra.Conf.Web("6688", api.WithTimeout(300, 300)).
			Static(static.WithEmbed(archive, staticFs), static.WithAutoRewrite()).
			Processor(processor.WithServicePrefix("/api")).
			Header(header.WithCrossDomain()).
			Jwt(jwt.WithMode("HS512"),
				jwt.WithSecret("9890ab73ef981e9ba7a9f777256f097f"),
				jwt.WithExpireAt(36000),
				jwt.WithAuthURL("/login"),
				jwt.WithHeader(),
				jwt.WithExcludes(auth.GetExcludes()...),
			)
		if err := ssov5.Bind(hydra.S.Web, "http://api.sso.hydra-cloud.com:6689",
			"sso5", "a519dae547a11824b6fac1625dcf04a3", "api"); err != nil {
			return err
		}
		return nil
	})
}
